package com.HZNU.Controller;

import com.HZNU.Service.DeptService;
import com.HZNU.spring_api.POJO.Dept;
import com.netflix.discovery.converters.Auto;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping("/dept/get/{id}")
    @HystrixCommand(fallbackMethod ="HystrixGet")
    public Dept get(@PathVariable("id") int id){
        Dept ret = deptService.selectByPrimaryKey(id);
        if(ret == null){
            throw  new RuntimeException("id不存在");
        }
        return ret;
    }

    //备选方案
    public Dept HystrixGet(@PathVariable("id")int id){
         return new Dept().setDeptno(id).setDname("没有这个人").setDbSource("not in mysql database");
    }



}
